from django.contrib import admin
from .models import Project, Group, Satellite


@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
    """
    项目管理界面
    """
    list_display = ['name', 'description', 'created_at', 'updated_at']
    list_filter = ['created_at']
    search_fields = ['name', 'description']
    readonly_fields = ['created_at', 'updated_at']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'description')
        }),
        ('时间信息', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',)
        })
    )


@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
    """
    组管理界面
    """
    list_display = ['name', 'project', 'description', 'created_at', 'updated_at']
    list_filter = ['project', 'created_at']
    search_fields = ['name', 'description', 'project__name']
    readonly_fields = ['created_at', 'updated_at']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'project', 'description')
        }),
        ('时间信息', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',)
        })
    )


@admin.register(Satellite)
class SatelliteAdmin(admin.ModelAdmin):
    """
    卫星管理界面
    """
    list_display = ['name', 'group', 'get_project', 'description', 'created_at', 'updated_at']
    list_filter = ['group__project', 'group', 'created_at']
    search_fields = ['name', 'description', 'group__name', 'group__project__name']
    readonly_fields = ['created_at', 'updated_at']
    
    def get_project(self, obj):
        return obj.group.project.name
    get_project.short_description = '所属项目'
    
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'group', 'description')
        }),
        ('时间信息', {
            'fields': ('created_at', 'updated_at'),
            'classes': ('collapse',)
        })
    )